//
//  EaseCallAttributeTextHelper.m
//  Linker
//
//  Created by hhsoft on 16/7/1.
//  Copyright © 2016年 www.huahansoft.com. All rights reserved.
//

#import "EaseCallAttributeTextHelper.h"
#import <UIKit/UIKit.h>

@implementation EaseCallAttributeTextHelper
    //callState:  0对方挂断(通话时长)/1对方没有响应/2对方拒接 3对方占线 4失败 5对方不在线 6自己拒绝 7自己挂断通话时长 8已取消 9未接听
+(NSAttributedString *)attStringWithCallResultText:(NSString *)text callType:(NSInteger)callType callState:(NSInteger)callState isSender:(BOOL)isSender{
    NSDictionary *textColorDic;
    UIImage *callImage;
    switch (callState) {
        case 0:{
            if (callType==0) {
                callImage=[UIImage imageNamed:@"chat_voice_call_receive.png"];
            }else{
                callImage=[UIImage imageNamed:@"chat_video_call_receive.png"];
            }
        }
            break;
        case 1:{
            if (callType==0) {
                callImage=[UIImage imageNamed:@"chat_voice_call_self.png"];
            }else{
                callImage=[UIImage imageNamed:@"chat_video_call_self.png"];
            }
        }
            break;
        case 2:{
            if (callType==0) {
                callImage=[UIImage imageNamed:@"chat_voice_call_self.png"];
            }else{
                callImage=[UIImage imageNamed:@"chat_video_call_self.png"];
            }
        }
            break;
        case 3:{
            if (callType==0) {
                callImage=[UIImage imageNamed:@"chat_voice_call_self.png"];
            }else{
                callImage=[UIImage imageNamed:@"chat_video_call_self.png"];
            }
        }
            break;
        case 4:{
            if (callType==0) {
                callImage=[UIImage imageNamed:@"chat_voice_call_self.png"];
            }else{
                callImage=[UIImage imageNamed:@"chat_video_call_self.png"];
            }
        }
            break;
        case 5:{
            if (callType==0) {
                callImage=[UIImage imageNamed:@"chat_voice_call_self.png"];
            }else{
                callImage=[UIImage imageNamed:@"chat_video_call_self.png"];
            }
        }
            break;
        case 6:{
            if (callType==0) {
                callImage=[UIImage imageNamed:@"chat_voice_call_self.png"];
            }else{
                callImage=[UIImage imageNamed:@"chat_video_call_self.png"];
            }
        }
            break;
        case 7:{
            if (callType==0) {
                callImage=[UIImage imageNamed:@"chat_voice_call_self.png"];
            }else{
                callImage=[UIImage imageNamed:@"chat_video_call_self.png"];
            }
        }
            break;
        case 8:{
            if (callType==0) {
                callImage=[UIImage imageNamed:@"chat_voice_call_self.png"];
            }else{
                callImage=[UIImage imageNamed:@"chat_video_call_self.png"];
            }
        }
            break;
        case 9:{
            if (callType==0) {
                callImage=[UIImage imageNamed:@"chat_voice_call_receive_back.png"];
            }else{
                callImage=[UIImage imageNamed:@"chat_video_call_receive_back.png"];
            }
            textColorDic=@{NSForegroundColorAttributeName:[UIColor colorWithRed:234.0f/255.0f green:101.0f/255.0f blue:118.0f/255.0f alpha:1]};
        }
            break;
            
        default:
            break;
    }
        
    NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil] ;
    textAttachment.bounds=CGRectMake(0, -5, (20*(callImage.size.width/callImage.size.height))+5, 20);
    textAttachment.image = callImage;
    NSAttributedString *textAttachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment] ;
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithAttributedString:textAttachmentString];
    NSString *stateStr=[NSString stringWithFormat:@" %@",text];
    NSAttributedString *attrState=[[NSAttributedString alloc] initWithString:stateStr attributes:textColorDic];
    [attrStr appendAttributedString:attrState];
    return attrStr;
}

@end
